angular.module('${menuCode}')
.filter('to_trusted', ['$sce', function ($sce) {
	return function (text) {
	    return $sce.trustAsHtml(text);
	};
}])
.controller("${widgetCode}Ctrl",function($scope,AppKit,$stateParams){
	$scope.piName=$stateParams.piName;
	$scope.loadWeeklyInfos =function (){
		var url = '/aeaipm/services/ProjWeekly/rest/findProjWeeklyInfos/'+$stateParams.piId+'/'+1;
		AppKit.getJsonApi(url).success(function(rspJson){
			$scope.weeklyInfos = rspJson;
			
			$scope.tabPages = rspJson[0].weeklyListPageSize;
			$scope.tabCount = rspJson[0].weeklyListSize;
			$scope.tabMores = true;
			
			if($scope.weeklyInfos.length == 0){
				$scope.receiveNoRecord = true;
			}else{
				$scope.receiveNoRecord = false;
			}
		})
	}
	$scope.loadWeeklyInfos();
	
	
	$scope.doReload = function(){
		$scope.tabPages = $scope.tabPages+1;
		var url = '/aeaipm/services/ProjWeekly/rest/findProjWeeklyInfos/'+$stateParams.piId+'/'+$scope.tabPages;
		AppKit.getJsonApi(url).success(function(rspJson){
			
			if ($scope.tabCount >= $scope.tabPages){
				for (var i=0;i < rspJson.length;i++){
					var obj = rspJson[i];
					$scope.weeklyInfos.push(obj);				
				}	
				$scope.tabMores = true;
			}else{
				$scope.tabMores = false;
			}
		}).finally(function(){
			AppKit.reloadOver($scope);
		});
	}
	
	$scope.hasMore = function(){
		return $scope.tabMores;
	}
	
});